import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/net/response/visitor_check/visitor_check_list_data.dart';
import 'package:ls_work/viewmodel/visitor_check/visitor_check_detail_view_model.dart';

import '../../widgets/dotted_line.dart';

class VisitorCheckDetailPage extends BaseStatefulMvvmWidget {
  final VisitorCheckListData? item;

  VisitorCheckDetailPage(this.item);

  @override
  State<StatefulWidget> createState() => _VisitorCheckDetailState();
}

class _VisitorCheckDetailState
    extends BaseMvvmState<VisitorCheckDetailViewModel, VisitorCheckDetailPage> {
  @override
  Widget buildLoadingContentView() {
    return Column(
      children: [
        ListView(
          children: [
            CommonText('来访人健康码', fontWeight: FontWeight.bold, textSize: 17)
                .addToContainer(
                    margin:
                        const EdgeInsets.only(left: 16, top: 10, bottom: 30)),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                Column(
                  children: [
                    Image.asset(
                      'images/health_code2.png',
                      width: 146,
                      height: 146,
                      package: 'visitor_scan_package',
                    ),
                    Container(
                      height: 10,
                    ),
                    CommonText('健康码')
                  ],
                ).setWeight(1),
                Column(
                  children: [
                    Image.asset(
                      'images/xingcheng.png',
                      width: 146,
                      height: 146,
                      package: 'visitor_scan_package',
                    ),
                    Container(
                      height: 10,
                    ),
                    CommonText('行程码')
                  ],
                ).setWeight(1),
              ],
            ),
            Container(
              height: 20,
            ),
            Container(
              height: 0.5,
              color: Colors.grey,
              width: double.infinity,
              margin: EdgeInsets.symmetric(horizontal: 10),
            ),
            IconTitleTextWidget(
              '来访时间:',
              height: 46,
              text: "2022-06-06 12:00:00",
              showArrow: false,
            ),
            dottedLine(),
            IconTitleTextWidget(
              '姓名:',
              height: 46,
              text: widget.item?.name??"",
              showArrow: false,
            ),
            dottedLine(),
            IconTitleTextWidget(
              '手机号:',
              height: 46,
              text: '18869978852',
              showArrow: false,
            ),
            dottedLine(),
            IconTitleTextWidget(
              '身份证号:',
              height: 46,
              text: "330726196711090987",
              showArrow: false,
            ),
            dottedLine(),
            IconTitleTextWidget(
              '来访事由:',
              height: 46,
              text: '家属探访',
              showArrow: false,
            ),
            dottedLine(),
            IconTitleTextWidget(
              '来访人数:',
              height: 46,
              text: "3",
              showArrow: false,
            ),
            dottedLine(),
            IconTitleTextWidget(
              '被访人姓名:',
              height: 46,
              text: widget.item?.old??"",
              showArrow: false,
            ),
            dottedLine(),
            IconTitleTextWidget(
              '车牌:',
              height: 46,
              text: "浙A6N8G3",
              showArrow: false,
            ),
            dottedLine(),
            Container(
              height: 20,
            ),

           viewModel.canClick?  Row(
              children: [
                ElevatedButton(
                    onPressed: () {
                      viewModel.refuse();
                    },
                    style: ButtonStyle(
                        minimumSize:
                        WidgetStateProperty.all(Size.fromHeight(50)),
                        backgroundColor:
                        WidgetStateProperty.all(Colors.white),
                        elevation: WidgetStateProperty.all(0),
                        shape: WidgetStateProperty.all(RoundedRectangleBorder(
                            side: BorderSide(color: Colors.blue),borderRadius: 8.borderRadius))),
                    child: CommonText("拒绝来访", textColor: Colors.blue))
                    .setWeight(1),
                Container(width: 20,),
                ElevatedButton(
                    onPressed: () {
                      viewModel.pass();
                    },
                    style: ButtonStyle(
                        minimumSize:
                        WidgetStateProperty.all(Size.fromHeight(50)),
                        backgroundColor:
                        WidgetStateProperty.all(Colors.blue),
                        elevation: WidgetStateProperty.all(0),
                        shape: WidgetStateProperty.all(RoundedRectangleBorder(
                            side: BorderSide(color: Colors.blue),borderRadius: 8.borderRadius))),
                    child: CommonText("审核通过", textColor: Colors.white))
                    .setWeight(1),
              ],
            ).addToContainer(margin: EdgeInsets.symmetric(horizontal: 16)):Container(),

            Container(height: 50,)
          ],
        ).setWeight(1),

      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(
        title: Text('访客审核'),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  VisitorCheckDetailViewModel createViewModel() {
    return VisitorCheckDetailViewModel(context);
  }

  @override
  void onRetryClick() {}

  Widget dottedLine() {
    return const DottedLine(
      height: 0.5,
    ).addToContainer(
        width: double.infinity,
        margin: const EdgeInsets.symmetric(horizontal: 10));
  }
}
